import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const {  $Lazy, $fn } = window
// ===================================================================== Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const Tips 		= $Lazy.load(()=>import('#tp/tips'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		//修改账期
		formData:[
			// 结算时获取列表搜索条件，取消弹窗结算账期字段 20211014 耿琰
			{ label: '结算账期',		name: 'phase_id', 	full:true, required:true, type: 'select', loading:true },
			{ label: '用户名',		name: 'account', 	full:true, required:true },
			{ label: '密码',			name: 'password', 	full:true, required:true, type:'password' },
		]
	}
	
	model = {}
	
	open = (data, way) => {
		const { formData } = this.state
		this.modal.open({ formRef:this.formRef })
		this.getSelect(data)
		this.submit = data
		this.setState(()=> (way ? { title:'结算', api:'bill/settlement'} : { title:'反结算', api:'bill/resettlement'}) )
		if(way){
			$fn.hideRows(formData,['phase_id'], true)
		}else{
			$fn.hideRows(formData,['phase_id'], false)
		}
		this.setState({ formData })
	}

	// 获取下拉数据
	getSelect = (data) => {
		const { formData } = this.state
		$cache.then( async f => {
			// 账期
			$fn.setRow(formData, 'phase_id', data ) 
			this.setState({ formData })
		})
	}
	
	render(){
		const { title, api } = this.state
		return (
			<>
				{FormModal.call(this,{ title, width:500, api, 
					prefix: (<Tips text='请输入用户名与密码进行账单结算' className = 'mb5' />) 
				})}
			</>
		)
	}
}

export default Index